<template>
	<view class="coupon_box">
		<view class="coupon text-grey shadow box11" v-for="(item,index) in coupon.rows" :key='index'>
			<view class="coupon_left">
				<view class="coupon_left_top">
					{{item.couponName}}
				</view>
			</view>
			<view class="coupon_right">
				<view class="coupon_right_top">
					<view class="coupon_right_top_left">		
						<view v-show="index != coupon_index">{{item.couponState}}</view>
						<view v-show="index == coupon_index">已使用</view>
						
					</view>
					<view class="coupon_right_top_right">
						菜品金额要大于优惠券金额
					</view>
				</view>
				<view class="coupon_right_buttom">
					<view class="">
						{{item.effectiveTime}}
					</view>
					<view class="coupon_right_buttom_button">
						<view v-show="index != coupon_index" @tap="Useitnow(index,item.id,item.concession,item.ids)">立即使用</view>
						<view v-show="index == coupon_index" @tap="UseitnowNo">取消使用</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				money: null, //餐品价格
				coupon: null, //优惠券
				CouponStatus: '',
			}
		},
		created() {
			this.selectUserContro()
		},
		onLoad(options) {
			this.money = options.money
		},
		computed: {
			...mapState(['openid', 'id', 'coupon_index']),
			
		},
		methods: {
			...mapMutations(['coupons']),
			selectUserContro() {
				this.request.selectUserContro({
					id: this.id
				}).then(res => {
					this.coupon = res
				})
			},
			Useitnow(index, id, concessions, ids) {
				if (this.money == null || this.money < concessions) {
					uni.showToast({
						icon: 'none',
						title: "菜品金额不满足优惠券的使用",
					})
					return false
				}
				if (this.money == concessions) {
					let moneycons = this.money - 0.01
					this.coupons({
						coupon_index:index,
						coupon_id:id,
						coupon_concessions:moneycons,
						coupon_ids:ids
					})
					uni.navigateBack({
						delta: 1
					});
					return false
				}
				this.coupons({
					coupon_index:index,
					coupon_id:id,
					coupon_concessions:concessions,
					coupon_ids:ids
				})
				uni.navigateBack({
					delta: 1
				});
			},
			UseitnowNo() {
				this.coupons({
					coupon_index:-1,
					coupon_id:'',
					coupon_concessions:0,
					coupon_ids:''
				})

			}
		}
	}
</script>

<style lang="scss">
	.coupon_box {
		padding: 10rpx;
	}

	.coupon {
		-webkit-box-shadow: 2px 2px 2px #3F536E;
		box-shadow: 1rpx 1rpx 7rpx #3F536E;
		padding: 10rpx 20rpx;
		display: -webkit-box;
		margin: 10rpx 20rpx;
		display: -webkit-flex;
		display: flex;
		border-radius: 13rpx;
		height: 190rpx;
		background-color: #FFFFFF;
	}

	.coupon_left {
		width: 178rpx;
		text-align: center;
		background-color: #39B54A;

		.coupon_left_top,
		.coupon_left_buttom {
			color: #FFFFFF;
			height: 50rpx;
			width: 178rpx;
			line-height: 150rpx;
		}

		.coupon_left_top {
			font-size: 30rpx;
			font-weight: 500;
		}

		.coupon_left_buttom {
			font-size: 24rpx;
		}
	}

	.coupon_right_buttom {
		margin-top: 50rpx;
	}

	.coupon_right {
		padding: 15rpx 10rpx;
		margin-left: 10rpx;
		width: 572rpx;
		line-height: 56rpx;
		font-size: 24rpx;

		.coupon_right_top,
		.coupon_right_buttom {
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.coupon_right_top {
			.coupon_right_top_left {
				width: 150rpx;
				height: 40rpx;
				line-height: 32rpx;
				text-align: center;
				color: #FFFFFF;
				background-color: #f37b1d;
				padding: 5rpx;
				border-radius: 25rpx;
			}
		}

		.coupon_right_buttom {
			.coupon_right_buttom_button {
				width: 150rpx;
				height: 48rpx;
				line-height: 40rpx;
				text-align: center;
				color: #f37b1d;
				border: 1rpx solid #f37b1d;
				padding: 5rpx;
				border-radius: 25rpx;
			}
		}
	}

	.box11 {
		height: 100px;
		background: #FFFFFF;
		border-radius: 10px;
		margin: 10px;
	}

	.shadow {
		position: relative;
		box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.3),
			0px 0px 20px rgba(0, 0, 0, 0.1) inset;
	}

	.shadow::before,
	.shadow::after {
		content: "";
		position: absolute;
		z-index: -1;
	}

	.shadow::before,
	.shadow::after {
		content: "";
		position: absolute;
		z-index: -1;
		bottom: 15px;
		left: 10px;
		width: 50%;
		height: 20%;
	}

	.shadow::before,
	.shadow::after {
		content: "";
		position: absolute;
		z-index: -1;
		bottom: 15px;
		left: 10px;
		width: 50%;
		height: 20%;
		box-shadow: 0 15px 10px rgba(0, 0, 0, 0.7);
		transform: rotate(-3deg);
	}

	.shadow::after {
		right: 10px;
		left: auto;
		transform: rotate(3deg);
	}
</style>
